const Koa = require("koa");
const cors = require("koa-cors");
const bodyParser = require("koa-bodyparser");
const logger = require("koa-logger");
const { JWT_SECRET, port } = require("./config");
const koajwt = require("koa-jwt");
const router = require("./router");
const app = new Koa();
app.use(logger());
app.use(cors());
app.use(bodyParser());

app.use(
  koajwt({
    secret: JWT_SECRET,
  }).unless({
    // 配置白名单
    path: [/\/user\/verify/, /\/user\/login/],
  })
);

app.use(router.routes(), router.allowedMethods());

app.listen(port, () => {
  console.log(`server is alerday ${port} start`);
});
